<?php

// +----------------------------------------------------------------------
// |ZBPHP[基于ThinkPHP6.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 http://www.benbenwangluo.com
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 铭畅软件 技术部 出品
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\common\model\Order;
use app\BaseController;
use think\facade\Db;

/** 
 * @Author: Bryant 
 * @Date: 2023-06-07 10:38:11 
 * @method post 
 * @title 支付回调 
 */
class Pay extends BaseController
{
    /** 
     * @Author: Bryant 
     * @Date: 2023-06-07 10:40:01 
     * @method post 
     * @title 微信APP异步回调 
     */
    function wxapp_notify() {
        $weChat = addons_action('WeChat', 'AppPay', 'init');
        try {
            $arr = $weChat->verifyNotify();
        } catch (\Exception $e) {
            $weChat->NotifyProcess(false, '支付异常');
        }
        //商户流程
        $order_no = $arr['out_trade_no'];
        $res = Order::verify($order_no, 'wxpay', $arr['transaction_id'], $arr['total_fee']);
        if(!$res){
            $weChat->NotifyProcess(false, '订单已支付或不存在');
        }
        $weChat->NotifyProcess(true, 'OK');
    }
}
